package com.xingdata.jjxc.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xingdata.jjxc.R;
import com.xingdata.jjxc.enty.ScaleEntity;
import com.xingdata.jjxc.views.ChartView;

public class ChartListViewAdapter extends BaseAdapter {
	private ArrayList<ScaleEntity> scaleEntities;
	private Context mContext;

	public ChartListViewAdapter(ArrayList<ScaleEntity> scaleEntities,
			Context mContext) {
		this.scaleEntities = scaleEntities;
		this.mContext = mContext;
	}

	@Override
	public int getCount() {
		return scaleEntities == null ? 0 : scaleEntities.size();
	}

	@Override
	public Object getItem(int position) {
		return scaleEntities == null ? null : scaleEntities.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		LayoutInflater mInflater = LayoutInflater.from(mContext);
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.carinfo_drivinghabits_item, null);
			holder.chartView = (ChartView) convertView
					.findViewById(R.id.mChartView);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.chartView.setViewInfo(scaleEntities.get(position), mContext);
		return convertView;
	}

	private class ViewHolder {
		public ChartView chartView;
		private TextView testView;
	}
}
